package xiaof.controller;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import xiaof.domain.User;

@Controller
//@RequestMapping("/user")
public class UserController {
    @RequestMapping("/quick3")
    @ResponseBody
    public String save3() throws JsonProcessingException {
      User user=new User();
      user.setName("xiaof");
      user.setAge(18);
      ObjectMapper objectMapper=new ObjectMapper();
      String json=objectMapper.writeValueAsString(user);
      return json;

    }


    @RequestMapping("/quick2")
    public ModelAndView save2(){
        /**
         * Model模型用于封装数据
         * View 视图用于展示页面
         */

        ModelAndView modelAndView=new ModelAndView();
        //设置视图名称
        modelAndView.setViewName("success");
        return modelAndView;
    }

    @RequestMapping("/quick")
    public String save(){
        System.out.println("save...");
        return "/success.jsp";
    }
}
